<? if($config_rsa_pubkey) { ?>
var rsa_pubkey = "<?=str_replace("\n", "\\n", $config_rsa_pubkey)?>";
<? } ?>
var config_prefix = '<?=$config_prefix?>';

<? if($config_force_https) { ?>
var href = location.href+"";
if(href.toLowerCase().indexOf("http://") != -1) {
	href = href.replace("http://", "https://");
	location.href = href;
}
<? } ?>


<? if($config_sendyzm_func) { ?>
var yzm_time = 30;
var yzm_first = true;
function set_yzmbt_time() {
	yzm_time--;
	if(yzm_time <= 0) {
		$("yzmbt").disabled = false;
		$("yzmbt").value = '重新发送';
	} else {
		$("yzmbt").value = yzm_time + '秒后重新获取';
		setTimeout(set_yzmbt_time, 1000);
	}
}
function resendYzm() {
	yzm_first = true;
	$G.setValue("yzm");
	doLogin();
}
<? } ?>
function doLogin() {
	var username = $G.getValue("username");
	var password = $G.getValue("password");
	<? if($config_sendyzm_func) { ?>
	var yzm = $G.getValue("yzm");
	<? } ?>
	if(username == '') {
		alert("请输入帐号！");
		return ;
	}
	if(password == '') {
		alert("请输入密码！");
		return ;
	}
	<? if($config_sendyzm_func) { ?>
	if(!yzm_first) {
		if(yzm == '') {
			alert("请输入验证码！");
			return ;
		}
	}
	<? } ?>
	$("loginBt").disabled = true;
	$G.ajax("?act=login&m=dologin", {'username': username, 'password': password<? if($config_sendyzm_func) { ?>, 'yzm': yzm<? } ?>}, function(rs) {
		$("loginBt").disabled = false;
		if(typeof(rs.status) !== 'undefined') {
			if(rs.status == 1) {
				<? if($config_sendyzm_func) { ?>
				if(yzm == '') {
					$("yzm_div").style.display = '';
					yzm_first = false;
					yzm_time = 30;
					$("yzmbt").value = yzm_time + '秒后重新获取';
					$("yzmbt").disabled = true;
					setTimeout(set_yzmbt_time, 1000);
					return ;
				}
				<? } ?>
				var token = rs.data.token;
				LocalStorage.setItem(config_prefix+'_admininc_token', token);
				//$G.httpPost("?", {}, "_self");
				<? if($config_index_url) { ?>
				location.href = '<?=$config_index_url?>';
				<? } else {?>
				location.href = '?';
				<? } ?>
			} else {
				alert(rs.message);
			}
		} else {
			alert("登录失败，请重试！");
		}
	}, 'json', 'POST');
}